package com.sqlcheck.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sqlcheck.entity.Project;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Optional;

@Mapper
public interface ProjectRepository extends BaseMapper<Project> {

    @Select("SELECT * FROM projects WHERE gitlab_project_id = #{gitlabProjectId} AND deleted = 0")
    Optional<Project> findByGitlabProjectId(@Param("gitlabProjectId") Long gitlabProjectId);

    @Select("SELECT * FROM projects WHERE owner_id = #{ownerId} AND deleted = 0 ORDER BY created_at DESC")
    List<Project> findByOwnerId(@Param("ownerId") Long ownerId);

    @Select("SELECT * FROM projects WHERE name LIKE CONCAT('%', #{name}, '%') AND deleted = 0")
    List<Project> findByNameContaining(@Param("name") String name);
}